<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <h3 id="root">
  </h3>
  <script>
    function createSSE(url) {
      const eventSource = new EventSource(url);
      eventSource.onmessage = function (event) {
        const data = JSON.parse(event?.data || "{}");
        if (data.type === "close") {
          eventSource.close();
        } else {
          const root = document.getElementById("root");
          root.innerText += data.msg;
        }
      };

      return eventSource;
    }
    const sse = createSSE("http://localhost:3001/sse");
  </script>
</body>

</html>